package com.example.fairytset;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

public class firstFragment extends Fragment {
        ArrayList<Con> listData=new ArrayList<>();
        MyListAdapter myListAdapter;
        View  contentView;
        public firstFragment() {

        }

        @Override
        public void onStart() {
            Log.d("TAG","onStart");
            demo();
            super.onStart();
        }
        private void demo()
        {
            listData.add(new Con("日前,国家卫健委有关负责人表示,我国正采取多"));
            listData.add(new Con("日前,国家卫健委有关负责人表示,我国正采取多"));
            listData.add(new Con("日前,国家卫健委有关负责人表示,我国正采取多"));
            listData.add(new Con("日前,国家卫健委有关负责人表示,我国正采取多"));

        }

        @Override
        public void onCreate(@Nullable Bundle savedInstanceState) {
            Log.d("TAG","onCreate");
            super.onCreate(savedInstanceState);
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState)
        {
            Log.d("TAG","onCreateView");
            //创建界面MsgFragment
            contentView=inflater.inflate(R.layout.firstpager_fragment,container,false);

            //界面的初始化
            myListAdapter=new MyListAdapter();
            ListView listView=contentView.findViewById(R.id.l1);
            listView.setAdapter(myListAdapter);
            return contentView;

        }

        public class Con
        {
            public String content;
            public Con(String content)
            {
                this.content=content;
            }
        }
        public class MyListAdapter extends BaseAdapter {

            @Override
            public int getCount() {
                return listData.size();
            }

            @Override
            public Object getItem(int position) {
                return listData.get(position);
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View converView, ViewGroup parent) {

                if (converView == null) {
                    converView = getLayoutInflater().inflate(R.layout.item, parent, false);
                }
                Con c = (Con) getItem(position);
                TextView textView = converView.findViewById(R.id.tx);
                textView.setText(c.content);

                return converView;
            }
        }

}
